//
//  WTUserCenter.m
//  UIViewTransformPoint
//
//  Created by codew on 5/9/21.
//

#import "WTUserCenter.h"

@interface WTUserCenter ()

{
    
    // 定义一个并发队列
    dispatch_queue_t concurrent_queue;
    // 用户数据中心, 可能有多个线程需要数据访问
    NSMutableDictionary *userCenterDic;
}

@end

@implementation WTUserCenter

- (instancetype)init
{
    self = [super init];
    
    if (self) {
        
        concurrent_queue = dispatch_queue_create("com.itopengl", DISPATCH_QUEUE_CONCURRENT);
        userCenterDic = [NSMutableDictionary dictionary];
    }
    
    return self;
}


- (id)wtObjectForKey:(NSString *)key
{
    __block id obj;
    
    // 同步读取指定数据
    dispatch_sync(concurrent_queue, ^{
       
        obj = [userCenterDic objectForKey:key];
    });
    
    return obj;
}


- (void)wtSetObject:(id)obj forKey:(NSString *)key
{
    // 异步栅栏调用设置数据
    
    dispatch_barrier_async(concurrent_queue, ^{
        
        [self->userCenterDic setObject:obj forKey:key];
    });

}

@end
